﻿@model IList<ExamPlat.Models.ExamQues>
@{
    ViewBag.Title = "Index";
}
<div>
    <form action="/ExamQues/Index">
        <table>
            <tr>
                <td><input type="text" id="searchTitle" name="searchTitle" value="@ViewBag.SearchTitle" placeholder="考题标题" /></td>
                <td style="padding-left:10px;"><input class="btn btn-primary" type="submit" value="查询" /></td>
                <td style="padding-left:10px;"><input type="button" value="增加" id="btnAdd" class="btn btn-primary" /></td>
            </tr>
        </table>
    </form>
</div>
<div>
    <table style="width:600px;">
        <tr><th>考题标题</th><th>考题时长</th><th>考题状态</th><th>单选题分值</th><th>多选题分值</th><th>对错题分值</th><th>操作</th></tr>
        @{
            if (Model != null)
            {
                foreach (var item in Model)
                {
                    var status = item.ExamQuesStatus ? "可用" : "不可用";
                    <tr>
                        <td>@item.ExamQuesTitle</td>
                        <td>@{@item.ExamQuesTime}分钟</td>
                        <td>@status</td>
                        <td>@item.SingleScore</td>
                        <td>@item.MultipleScore</td>
                        <td>@item.JudgeScore</td>
                        <td>
                            <a href="javascript:;" onclick="EditExamQues(@item.ID)">修改</a> <span style="padding-left:10px;">
                                <a href="javascript:;" onclick="DelExamQuesTitle(@item.ID,'@item.ExamQuesTitle')">删除</a>
                            </span>
                            <a href="javascript:;" onclick="PreExamQues(@item.ID)">预览</a>
                        </td>
                    </tr>
        }
    }
        }
    </table>
</div>
<script type="text/javascript">
    function DelExamQuesTitle(id, name) {
        if (confirm('删除考题会一起删掉该考题下面的问题，确定删除' + name + '?')) {
            $.ajax({
                type: "post",  //提交方式
                url: "Delete",//路径
                data: { "id": id },//数据，这里使用的是Json格式进行传输
                dataType: "json",
                success: function (result) {//返回数据根据结果进行相应的处理
                    alert(result.msg);
                    window.location.reload();
                }
            });
        }
    }

    function EditExamQues(id) {
        window.location = "/ExamQues/Edit?id=" + id + "&searchTitle=" + encodeURIComponent($("#searchTitle").val());
    }

    $(function () {
        $("#btnAdd").click(function () {
            window.location = "/ExamQues/Create?searchTitle=" + encodeURIComponent($("#searchTitle").val());
        });
    });

    function PreExamQues(id)
    {
        window.open("http://"+window.location.host+"/ExamQues/Preview?id="+id);
    }
</script>